/**
 * 订单管理 交易订单
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>提现管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="userKey" placeholder="输入用户昵称/手机号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="status" placeholder="请选择">
          <el-option v-for="type in payType" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-form :inline="true" class="user-search">
      <el-form-item label="提现手续费%：">
        <el-input size="small" v-model="rate" placeholder=""></el-input>
      </el-form-item>


      <el-form-item>
        <el-button size="small" type="primary"  @click="setServiceCharge">确认设置</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
      element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="index" width="60">
      </el-table-column>
      <el-table-column prop="addTime" label="头像" width="100">
        <template slot-scope="scope">
          <el-image style="width: 50px; height: 50px;border-radius: 50px;" :src="scope.row.headPortrait"></el-image>
        </template>
      </el-table-column>
      <el-table-column sortable prop="username" label="用户" width="100">
      </el-table-column>
      <el-table-column sortable prop="mobile" label="手机号" width="100">
      </el-table-column>
      <el-table-column sortable prop="status" label="状态" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0">处理中</div>
          <div v-if="scope.row.status == 1">提现成功</div>
          <div v-if="scope.row.status == 2">提现失败</div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="goodsPrice" label="提现金额" width="80" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ scope.row.money / 100 }}</div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="goodsPrice" label="手续费" width="80" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ scope.row.serviceCharge / 100 }}</div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="goodsPrice" label="实际金额到账" width="80" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ scope.row.actualMoney / 100 }}</div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="type" label="提现方式" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.type == 0">支付宝</div>
          <div v-if="scope.row.type == 1">银行卡</div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="alipayAccount" label="支付宝账号" width="140" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="bankCard" label="银行卡账号" width="140" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="bankName" label="开户行" width="140" show-overflow-tooltip>
      </el-table-column>

      <el-table-column sortable prop="bankBranch" label="支行" width="140" show-overflow-tooltip>
      </el-table-column>

        


      <el-table-column sortable prop="addTime" label="创建时间" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ transformDate(scope.row.createTime) }}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope" v-if="scope.row.status == 0">
          <el-button size="mini" @click="setWithdraw(scope.$index, scope.row)">确认打款</el-button>
          <el-button size="mini" type="danger" @click="cancelWithdraw(scope.$index, scope.row)">取消打款</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->

  </div>
</template>

<script>
import { getWithdrawList ,setWithdraw,setServiceCharge} from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '预览',
      userKey: "",
      status: 0,
      payType: [
        { key: '请选择', value: 0 },
        { key: '处理中', value: 1 },
        { key: '提现成功', value: 2 },
        { key: '提现失败', value: 3 }
      ],

      rate:"",

      formInline: {
        page: 1,
        limit: 10,
        machineNo: '',
        orderNo: '',
        transId: '',
        payType: 0,
        orderStatus: 0,
        token: localStorage.getItem('logintoken')
      },


      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 20,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getWithdrawList(1)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {


    // 获取列表
    getWithdrawList(page) {
      this.loading = true;
      var parameter = {
        userKey: this.userKey,
        status: this.status - 1,
        page: (page - 1) * 20,
      };
      console.log('parameter',parameter)
      getWithdrawList(parameter).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.listData = res.data.list;
          this.rate = res.data.rate/100;
          this.pageparm.currentPage = page;
          this.pageparm.total = res.data.count;
          return;
        }
        this.$message({
          type: "info",
          message: res.msg,
        });
      });
    },
    // 设置提现手续费
    setServiceCharge() {
      this.loading = true;
      var parameter = {
        rate: this.rate*100,
        id: 1
      };
      setServiceCharge(parameter).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: res.msg,
          });
          return;
        }
        this.$message({
          type: "info",
          message: res.msg,
        });
      });
    },



    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getWithdrawList(parm.currentPage)
    },
    // 搜索事件
    search() {
      this.getWithdrawList(1)
    },
    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true
      this.editForm = row
    },
    cancelWithdraw(index, row) {
      this.$confirm('确定取消打款吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          setWithdraw({id:row.id,status:2})
            .then(res => {
              if (res.code==200) {
                this.getWithdrawList(1)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    setWithdraw(index, row) {
      this.$confirm('确定已经打款了吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          setWithdraw({id:row.id,status:1})
            .then(res => {
              if (res.code==200) {
                this.getWithdrawList(1)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}
</style>

 
 

 